package com.ruoyi.web.controller.material.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.controller.material.entity.ylProductCategory;
import org.apache.ibatis.annotations.Mapper;

/**
 * 物品分类Mapper接口
 *
 * @author jzx
 * @date 2025-10-22
 */
@Mapper
public interface YlProductCategoryMapper extends BaseMapper<ylProductCategory> {
    /**
     * 判断名称是否重复
     *
     * @param categoryName
     * @return
     */
    default boolean getCategoryName(String categoryName, String id) {
        if (StringUtils.isNotEmpty(id)) {
            return selectCount(new LambdaQueryWrapper<ylProductCategory>().eq(ylProductCategory::getCategoryName, categoryName).ne(ylProductCategory::getId, id)) > 0;
        }
        return selectCount(new LambdaQueryWrapper<ylProductCategory>().eq(ylProductCategory::getCategoryName, categoryName)) > 0;
    }

    ;

    /**
     * 根据id查询分类名称
     *
     * @param productCategoryId
     * @return
     */
    default String getProductCategoryName(Long productCategoryId) {
        ylProductCategory ylProductCategory = selectById(productCategoryId);
        return ylProductCategory == null ? null : ylProductCategory.getCategoryName();
    }

    ;


}
